﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using WineModel;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
using System.Collections;

namespace WineDAL
{
   public  class WineShopDAL
    {
        SQLHelper helper = new SQLHelper();
        /// <summary>
        /// 显示购物车信息
        /// </summary>
        /// <returns></returns>
        public ArrayList ShopShow(int id)
        {
            SqlParameter par = new SqlParameter("@id", id);
            DataTable table = helper.ExecDataTable_Proc("Shop_show", par);
            JavaScriptSerializer jss = new JavaScriptSerializer();
            System.Collections.ArrayList dic = new System.Collections.ArrayList();
            foreach (DataRow dr in table.Rows)
            {
                System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
                foreach (DataColumn dc in table.Columns)
                {
                    drow.Add(dc.ColumnName, dr[dc.ColumnName]);
                }
                dic.Add(drow);
            }
            return dic;      
        }
        /// <summary>
        /// 购物车商品添加
        /// </summary>
        /// <param name="ss"></param>
        /// <returns></returns>
        public int ShopAdd(Shop ss)
        {
            SqlParameter[] pare = new SqlParameter[]{
               new SqlParameter("@GoodsNum",SqlDbType.Int,4),
               new SqlParameter("@GoodsPrice",SqlDbType.Decimal,20),
               new SqlParameter("@ShopDate",SqlDbType.DateTime),
               new SqlParameter("@UsersID",SqlDbType.Int,4),
               new SqlParameter("@GoodsID",SqlDbType.Int,4)
              
          };
            pare[0].Value = ss.GoodsNum;
            pare[1].Value = ss.GoodsPrice;
            pare[2].Value = ss.ShopDate;
            pare[3].Value = ss.UsersID;
            pare[4].Value = ss.GoodsID;
            return helper.ExecNonquery_Proc("Shop_Add", pare);
        }
       /// <summary>
       /// 删除购物车商品
       /// </summary>
       /// <param name="shopid"></param>
       /// <returns></returns>
        public int ShopDelete(int shopid)
        {
            SqlParameter[] pare = new SqlParameter[]{
            new SqlParameter("@id",shopid)
           };
            return helper.ExecNonquery_Proc("Shop_Delete", pare);
        }
    }
}
